<?php

// 用户判断
class index
{

    protected $now;
    protected $switch = 1;
    protected $extraList = [
        ['type'=>'wechat','name'=>'xinglin','title'=>'杏林方剂学','path'=>'weixin://dl/business/?t=NHFk4Jv1Nnd','image'=>'http://cdn.yqdhz.com/jingyue/sucai/sucai1.png']
    ];
    public function __construct()
    {
        $this->now = time();
        $params = $_REQUEST;
        if (empty($params['app_version'])) {
            $params = json_decode(file_get_contents("php://input"), true);
        }
        $this->params = $params;
    }

    public function success($info, $data = [], $code = 1): void
    {
        header('Content-Type:application/json; charset=utf-8');
        $result = ['code' => $code, 'info' => $info, 'data' => $data];
        echo json_encode($result);
        die();
    }

    public function exc()
    {
        $params = $this->params;
        try {
            file_put_contents('./log/' . date('Ymd') . '.log', 'extra:'.json_encode($params) . "\r\n", FILE_APPEND);
        } catch (Exception $e) {
        }
        $row = [];
        if($this->switch == 1){
            $list = $this->extraList;
        }else{
            $list = [];
        }
        if(count($list) > 0){
            $rand = mt_rand(0,count($list) - 1);
            $row = $list[$rand];
        }
        $row['isShow'] = $this->switch;
        $this->success('success',['row' => $row]);

    }
}

$wap = new index();
$wap->exc();
?>
